//
//  HKLoginRegisterViewController.m
//  BaiSiBuDeJie
//
//  Created by 胡锦涛 on 2018/12/2.
//  Copyright © 2018 胡锦涛. All rights reserved.
//

#import "HKLoginRegisterViewController.h"
#import "HKLoginRegisterView.h"
#import "HKFastLoginView.h"
@interface HKLoginRegisterViewController ()
@property (weak, nonatomic) IBOutlet UIView *middleView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadCons;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@end

@implementation HKLoginRegisterViewController
- (IBAction)close:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)clickRegister:(UIButton *)sender {
    sender.selected = !sender.selected;
    //平移中间View
    _leadCons.constant = _leadCons.constant == 0 ? - self.middleView.width * 0.5 : 0;
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
}

//1.划分结构(顶部 中间 底部)
//2.占位视图思想(分块)
//3.越复杂的界面 越要封装(复用)
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /*
      屏幕适配：
     1.一个View从xib加载,需不需要重新固定尺寸 一定要在外部再确定下
     2.在ViewDidLoad设置Frame好不好, 开发中一般在viewDidLayoutSubviews布局子控件 设置Frame
     */
    self.view.backgroundColor = kRedColor;
    
    // 1.创建登录view
    HKLoginRegisterView *loginView = [HKLoginRegisterView loginView];
    // 添加到中间的view
    [self.middleView addSubview:loginView];
    
    // 2.添加注册界面
    HKLoginRegisterView *registerView = [HKLoginRegisterView registerView];
    registerView.x = self.middleView.width * 0.5;
    // 添加到中间的view
    [self.middleView addSubview:registerView];
    
    //3. 添加快速登录view
    HKFastLoginView *fastLoginView = [HKFastLoginView fastLoginView];
    // 添加到底部的view
    [self.bottomView addSubview:fastLoginView];
    
    /*
     1.文本框光标变成白色
     2.文本框开始编辑的时候, 占位文字颜色编程白色
     */
}
// viewDidLayoutSubviews:才会根据布局调整控件的尺寸
- (void)viewDidLayoutSubviews
{
    // 一定要调用super
    [super viewDidLayoutSubviews];
    
    HKLoginRegisterView *loginView = self.middleView.subviews[0];
    loginView.frame = CGRectMake(0, 0, self.middleView.width * 0.5, self.middleView.height);
    
    HKLoginRegisterView *registerView = self.middleView.subviews[1];
    registerView.frame = CGRectMake( self.middleView.width * 0.5, 0,self.middleView.width * 0.5, self.middleView.height);
    
    // 设置快速登录
    HKFastLoginView *fastLoginView = self.bottomView.subviews.firstObject;
    fastLoginView.frame = self.bottomView.bounds;
}
@end
